/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package com.entities;

import java.io.Serializable;
import java.util.Date;
import java.util.List;
import javax.persistence.Basic;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.NamedStoredProcedureQueries;
import javax.persistence.NamedStoredProcedureQuery;
import javax.persistence.OneToMany;
import javax.persistence.ParameterMode;
import javax.persistence.StoredProcedureParameter;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlTransient;

/**
 *
 * @author Tuan Long
 */
@Entity
@Table(name = "Employee")
@XmlRootElement
@NamedQueries({
    @NamedQuery(name = "Employee.findAll", query = "SELECT e FROM Employee e"),
    @NamedQuery(name = "Employee.findByUsername", query = "SELECT e FROM Employee e WHERE e.username = :username"),
    @NamedQuery(name = "Employee.findByPassword", query = "SELECT e FROM Employee e WHERE e.password = :password"),
    @NamedQuery(name = "Employee.findByEmail", query = "SELECT e FROM Employee e WHERE e.email = :email"),
    @NamedQuery(name = "Employee.findByFullname", query = "SELECT e FROM Employee e WHERE e.fullname = :fullname"),
    @NamedQuery(name = "Employee.findByGender", query = "SELECT e FROM Employee e WHERE e.gender = :gender"),
    @NamedQuery(name = "Employee.findByBirthdate", query = "SELECT e FROM Employee e WHERE e.birthdate = :birthdate"),
    @NamedQuery(name = "Employee.findByPhone", query = "SELECT e FROM Employee e WHERE e.phone = :phone"),
    @NamedQuery(name = "Employee.findByMobilephone", query = "SELECT e FROM Employee e WHERE e.mobilephone = :mobilephone"),
    @NamedQuery(name = "Employee.findByAddress", query = "SELECT e FROM Employee e WHERE e.address = :address"),
    @NamedQuery(name = "Employee.findByIdentityCard", query = "SELECT e FROM Employee e WHERE e.identityCard = :identityCard"),
    @NamedQuery(name = "Employee.findByJoinInDate", query = "SELECT e FROM Employee e WHERE e.joinInDate = :joinInDate"),
    @NamedQuery(name = "Employee.findByPosition", query = "SELECT e FROM Employee e WHERE e.position = :position"),
    @NamedQuery(name = "Employee.findByDepartments", query = "SELECT e FROM Employee e WHERE e.departments = :departments"),
    @NamedQuery(name = "Employee.findByGroups", query = "SELECT e FROM Employee e WHERE e.groups = :groups"),
    @NamedQuery(name = "Employee.findByStatus", query = "SELECT e FROM Employee e WHERE e.status = :status"),
    @NamedQuery(name = "Employee.findByOnline", query = "SELECT e FROM Employee e WHERE e.online = :online"),
    @NamedQuery(name = "Employee.findByLogged", query = "SELECT e FROM Employee e WHERE e.logged = :logged"),
    @NamedQuery(name = "Employee.findByAvatar", query = "SELECT e FROM Employee e WHERE e.avatar = :avatar")})
@NamedStoredProcedureQueries({
    @NamedStoredProcedureQuery(name="Employee.createNewEmployee",procedureName = "sp_createNewEmployee",parameters = {
       @StoredProcedureParameter(name="username",mode=ParameterMode.IN,type=String.class),
       @StoredProcedureParameter(name="password",mode=ParameterMode.IN,type=String.class),
       @StoredProcedureParameter(name="email",mode=ParameterMode.IN,type=String.class),
       @StoredProcedureParameter(name="fullname",mode=ParameterMode.IN,type=String.class),
       @StoredProcedureParameter(name="gender",mode=ParameterMode.IN,type=String.class),
       @StoredProcedureParameter(name="birthday",mode=ParameterMode.IN,type=Date.class),
       @StoredProcedureParameter(name="phone",mode=ParameterMode.IN,type=String.class),
       @StoredProcedureParameter(name="mobile",mode=ParameterMode.IN,type=String.class),
       @StoredProcedureParameter(name="address",mode=ParameterMode.IN,type=String.class),
       @StoredProcedureParameter(name="indentitycard",mode=ParameterMode.IN,type=String.class),
       @StoredProcedureParameter(name="position",mode=ParameterMode.IN,type=String.class),
       @StoredProcedureParameter(name="department",mode=ParameterMode.IN,type=String.class),
       @StoredProcedureParameter(name="groups",mode=ParameterMode.IN,type=String.class),
       @StoredProcedureParameter(name="avatar",mode=ParameterMode.IN,type=String.class)
    }),
    @NamedStoredProcedureQuery(name = "Employee.changeEmployeePassword", procedureName = "sp_changeEmployeePassword", parameters = {
        @StoredProcedureParameter(name="username",mode = ParameterMode.IN,type = String.class),
        @StoredProcedureParameter(name="password",mode = ParameterMode.IN,type = String.class)
    })
})
public class Employee implements Serializable {
    private static final long serialVersionUID = 1L;
    @Id
    @Basic(optional = false)
    @NotNull
    @Size(min = 1, max = 50)
    @Column(name = "Username")
    private String username;
    @Basic(optional = false)
    @NotNull
    @Size(min = 1, max = 50)
    @Column(name = "Password")
    private String password;
    // @Pattern(regexp="[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?", message="Invalid email")//if the field contains email address consider using this annotation to enforce field validation
    @Basic(optional = false)
    @NotNull
    @Size(min = 1, max = 50)
    @Column(name = "Email")
    private String email;
    @Basic(optional = false)
    @NotNull
    @Size(min = 1, max = 50)
    @Column(name = "Fullname")
    private String fullname;
    @Basic(optional = false)
    @NotNull
    @Size(min = 1, max = 20)
    @Column(name = "Gender")
    private String gender;
    @Basic(optional = false)
    @NotNull
    @Column(name = "Birthdate")
    @Temporal(TemporalType.TIMESTAMP)
    private Date birthdate;
    // @Pattern(regexp="^\\(?(\\d{3})\\)?[- ]?(\\d{3})[- ]?(\\d{4})$", message="Invalid phone/fax format, should be as xxx-xxx-xxxx")//if the field contains phone or fax number consider using this annotation to enforce field validation
    @Basic(optional = false)
    @NotNull
    @Size(min = 1, max = 20)
    @Column(name = "Phone")
    private String phone;
    @Basic(optional = false)
    @NotNull
    @Size(min = 1, max = 20)
    @Column(name = "Mobilephone")
    private String mobilephone;
    @Basic(optional = false)
    @NotNull
    @Size(min = 1, max = 100)
    @Column(name = "Address")
    private String address;
    @Basic(optional = false)
    @NotNull
    @Size(min = 1, max = 20)
    @Column(name = "IdentityCard")
    private String identityCard;
    @Column(name = "JoinInDate")
    @Temporal(TemporalType.TIMESTAMP)
    private Date joinInDate;
    @Size(max = 100)
    @Column(name = "Position")
    private String position;
    @Size(max = 100)
    @Column(name = "Departments")
    private String departments;
    @Size(max = 200)
    @Column(name = "Groups")
    private String groups;
    @Size(max = 20)
    @Column(name = "Status")
    private String status;
    @Column(name = "Online")
    private Boolean online;
    @Column(name = "Logged")
    @Temporal(TemporalType.TIMESTAMP)
    private Date logged;
    @Size(max = 200)
    @Column(name = "Avatar")
    private String avatar;
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "username")
    private List<ContactMessage> contactMessageList;
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "username")
    private List<EventRegistration> eventRegistrationList;
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "username")
    private List<PictureLibrary> pictureLibraryList;
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "username")
    private List<EventComment> eventCommentList;
    @OneToMany(mappedBy = "username")
    private List<EventGift> eventGiftList;

    public Employee() {
    }

    public Employee(String username) {
        this.username = username;
    }

    public Employee(String username, String password, String email, String fullname, String gender, Date birthdate, String phone, String mobilephone, String address, String identityCard, Date joinInDate, String position, String departments, String groups, String status, Boolean online, Date logged, String avatar) {
        this.username = username;
        this.password = password;
        this.email = email;
        this.fullname = fullname;
        this.gender = gender;
        this.birthdate = birthdate;
        this.phone = phone;
        this.mobilephone = mobilephone;
        this.address = address;
        this.identityCard = identityCard;
        this.joinInDate = joinInDate;
        this.position = position;
        this.departments = departments;
        this.groups = groups;
        this.status = status;
        this.online = online;
        this.logged = logged;
        this.avatar = avatar;
    }

    public Employee(String username, String password, String email, String fullname, String gender, Date birthdate, String phone, String mobilephone, String address, String identityCard) {
        this.username = username;
        this.password = password;
        this.email = email;
        this.fullname = fullname;
        this.gender = gender;
        this.birthdate = birthdate;
        this.phone = phone;
        this.mobilephone = mobilephone;
        this.address = address;
        this.identityCard = identityCard;
    }

    public String getUsername() {
        return username;
    }

    public void setUsername(String username) {
        this.username = username;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    public String getEmail() {
        return email;
    }

    public void setEmail(String email) {
        this.email = email;
    }

    public String getFullname() {
        return fullname;
    }

    public void setFullname(String fullname) {
        this.fullname = fullname;
    }

    public String getGender() {
        return gender;
    }

    public void setGender(String gender) {
        this.gender = gender;
    }

    public Date getBirthdate() {
        return birthdate;
    }

    public void setBirthdate(Date birthdate) {
        this.birthdate = birthdate;
    }

    public String getPhone() {
        return phone;
    }

    public void setPhone(String phone) {
        this.phone = phone;
    }

    public String getMobilephone() {
        return mobilephone;
    }

    public void setMobilephone(String mobilephone) {
        this.mobilephone = mobilephone;
    }

    public String getAddress() {
        return address;
    }

    public void setAddress(String address) {
        this.address = address;
    }

    public String getIdentityCard() {
        return identityCard;
    }

    public void setIdentityCard(String identityCard) {
        this.identityCard = identityCard;
    }

    public Date getJoinInDate() {
        return joinInDate;
    }

    public void setJoinInDate(Date joinInDate) {
        this.joinInDate = joinInDate;
    }

    public String getPosition() {
        return position;
    }

    public void setPosition(String position) {
        this.position = position;
    }

    public String getDepartments() {
        return departments;
    }

    public void setDepartments(String departments) {
        this.departments = departments;
    }

    public String getGroups() {
        return groups;
    }

    public void setGroups(String groups) {
        this.groups = groups;
    }

    public String getStatus() {
        return status;
    }

    public void setStatus(String status) {
        this.status = status;
    }

    public Boolean getOnline() {
        return online;
    }

    public void setOnline(Boolean online) {
        this.online = online;
    }

    public Date getLogged() {
        return logged;
    }

    public void setLogged(Date logged) {
        this.logged = logged;
    }

    public String getAvatar() {
        return avatar;
    }

    public void setAvatar(String avatar) {
        this.avatar = avatar;
    }

    @XmlTransient
    public List<ContactMessage> getContactMessageList() {
        return contactMessageList;
    }

    public void setContactMessageList(List<ContactMessage> contactMessageList) {
        this.contactMessageList = contactMessageList;
    }

    @XmlTransient
    public List<EventRegistration> getEventRegistrationList() {
        return eventRegistrationList;
    }

    public void setEventRegistrationList(List<EventRegistration> eventRegistrationList) {
        this.eventRegistrationList = eventRegistrationList;
    }

    @XmlTransient
    public List<PictureLibrary> getPictureLibraryList() {
        return pictureLibraryList;
    }

    public void setPictureLibraryList(List<PictureLibrary> pictureLibraryList) {
        this.pictureLibraryList = pictureLibraryList;
    }

    @XmlTransient
    public List<EventComment> getEventCommentList() {
        return eventCommentList;
    }

    public void setEventCommentList(List<EventComment> eventCommentList) {
        this.eventCommentList = eventCommentList;
    }

    @XmlTransient
    public List<EventGift> getEventGiftList() {
        return eventGiftList;
    }

    public void setEventGiftList(List<EventGift> eventGiftList) {
        this.eventGiftList = eventGiftList;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (username != null ? username.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Employee)) {
            return false;
        }
        Employee other = (Employee) object;
        if ((this.username == null && other.username != null) || (this.username != null && !this.username.equals(other.username))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "com.entities.Employee[ username=" + username + " ]";
    }
    
}
